// pages/team/team.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    codephone: '01089557599'
  },
    //保存照片
  baocun:function(){
    wx.downloadFile({
      url: app.globalData.serviceUrl + '/wxminapp/api/getWxMinCodeImageBuffer/?code=' + this.data.codephone,
      success: function (res) {
        // console.log(res);
        console.log(res.tempFilePath);
        var erweima = res.tempFilePath;

          wx.saveImageToPhotosAlbum({
            filePath: erweima,
            success: function (data) {
              wx.showToast({
                title: "图片保存成功",
              })
            }, fail: function (res) {
              wx.showToast({
                title: "图片保存失败",
              })
            }
          })


      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;

    if (options.code) {
      that.data.codephone = options.code;
    }

    console.log('code=' + that.data.codephone);

    that.setData({
      mycode: app.globalData.serviceUrl + '/wxminapp/api/getWxMinCodeImageBuffer/?code=' + that.data.codephone
    })

    wx.request({
      url: app.globalData.wancheURL + 'getAllUserCode',
      data: {
        code: that.data.codephone
      },
      method: 'GET',
      success: function (res) {
        that.setData({ listshow: res.data })
      }
    })
  },

  previewImg: function (e) {
    var code = this.data.codephone;
    console.log('team 点击图片：' + code);
    wx.previewImage({
      current: app.globalData.serviceUrl + '/wxminapp/api/getWxMinCodeImageBuffer/?code=' + code, // 当前显示图片的http链接
      urls: [app.globalData.serviceUrl + '/wxminapp/api/getWxMinCodeImageBuffer/?code=' + code] // 需要预览的图片http链接列表
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    if (app.globalData.userInfo != null) {

      return {
        title: "0首付，申请买车！",
        imageUrl: "https://assets.puxiang.com/uploads/photo/image/153645/porsche-zoom__1_.jpg-photo_sp",
        path: "/pages/register/register?scene=code%3d" + app.globalData.userInfo.mobile,
        success: function (res) {
          var shareTickets = res.shareTickets;
          if (shareTickets.length == 0) {
            return false;
          }
          wx.getShareInfo({
            shareTicket: shareTickets[0],
            success: function (res) {
              var encryptedData = res.encryptedData;
              var iv = res.iv;
            }
          })
        },
        fail: function (res) {
          // 转发失败
          console.log(res);
        }
      }
    }
  }
})